package answer;

import java.util.Random;

/**
 * 
 * 编程生产 100 个 1到 6 之间的随机数，统计 1到 6 每个数出现的概率。
 */

public class Answer7 {
	public static void main(String[] args) {
		Random random = new Random();
		int sum;
		int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0;
		for (int i = 0; i < 100; i++) {
			sum = random.nextInt(6) + 1;
			if (sum == 1) {
				sum1++;
			} else if (sum == 2) {
				sum2++;
			} else if (sum == 3) {
				sum3++;
			} else if (sum == 4) {
				sum4++;
			} else if (sum == 5) {
				sum5++;
			} else if (sum == 6) {
				sum6++;
			}

		}
		System.out.println("sum1=" + sum1 + " sum2=" + sum2 + " sum3=" + sum3 + " sum4=" + sum4 + " sum5=" + sum5
				+ "sum6=" + sum6);
		System.out.println("出现1的概率：" + (float)sum1 / 100);
		System.out.println("出现2的概率：" + (float)sum2 / 100);
		System.out.println("出现3的概率：" + (float)sum3 / 100);
		System.out.println("出现4的概率：" + (float)sum4 / 100);
		System.out.println("出现5的概率：" + (float)sum5 / 100);
		System.out.println("出现6的概率：" + (float)sum6 / 100);
	}
}
